<style>
    .layui-form-item{
        margin-bottom: 0px;
    }
    legend{
        font-size: 14px !important;
        color: #009688;
        font-weight: bold !important;
    }
</style>
<div class="layui-layout layui-layout-admin" style="padding-left: 40px;margin-top: 20px;">
    <div class="layui-btn-container mw200">
        {{if eq $.task.Status 2}}
            <button lay-submit class="layui-btn  layui-btn-sm " lay-filter="audit">审核通过</button>
            <button lay-submit class="layui-btn  layui-btn-sm layui-btn-danger" lay-filter="nopass">审核不通过</button>
        {{end}}
        {{if eq $.task.Status 1}}
            <button lay-submit class="layui-btn  layui-btn-sm layui-btn-danger" lay-filter="pause">暂停任务</button>
        {{end}}
        {{if eq $.task.Status 0}}
            <button lay-submit class="layui-btn  layui-btn-sm layui-btn-danger" lay-filter="start">启动任务</button>
        {{end}}

        <button lay-submit class="layui-btn  layui-btn-sm " lay-filter="edit">编辑任务</button>
        <button lay-submit class="layui-btn  layui-btn-sm " lay-filter="run">测试执行</button>
        <button lay-submit class="layui-btn  layui-btn-sm " lay-filter="log">任务日志</button>
        <button lay-submit class="layui-btn  layui-btn-sm " lay-filter="copy">复制任务</button>
    </div>

    <div class="layui-layout layui-layout-admin" style="padding-left: 40px;margin-top: 20px;padding-right: 10px;">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>{{.task.TaskName}}（#{{.task.Id}}）任务详细</legend>
        </fieldset>
        <table class="layui-table" lay-skin="nob" lay-size="sm">
            <colgroup>
                <col width="80">
                <col width="400">
                <col>
            </colgroup>

            <tbody>

            <tr>
                <td>任务说明</td>
                <td>{{.task.TaskName}}</td>
                <td></td>
            </tr>
            <tr>
                <td>任务状态</td>
                <td>{{.TextStatus|str2html}}</td>
                <td></td>
            </tr>

            <tr>
                <td>执行次数</td>
                <td>{{.task.ExecuteTimes}}</td>
                <td></td>
            </tr>

            <tr>
                <td>任务分组</td>
                <td> {{.GroupName}}</td>
                <td></td>
            </tr>
            <tr>
                <td>服务资源</td>
                <td> {{.serverName}}</td>
                <td></td>
            </tr>
            <tr>
                <td>是否单例</td>
                <td>{{if eq .task.Concurrent 0}}是{{end}} {{if eq .task.Concurrent 1}}否{{end}}</td>
                <td></td>
            </tr>
            <tr>
                <td>执行时间</td>
                <td> {{.task.CronSpec}}</td>
                <td></td>
            </tr>

            <tr>
                <td>命令脚本</td>
                <td>{{.task.Command}}</td>
                <td></td>
            </tr>

            <tr>
                <td>超时设置</td>
                <td>{{.task.Timeout}}</td>
                <td></td>
            </tr>

            <tr>
                <td>出错通知</td>
                <td>{{if eq .task.IsNotify 0}}否{{end}} {{if eq .task.IsNotify 1}}是{{end}}</td>
                <td></td>
            </tr>

            {{if eq .task.IsNotify 1}}
            <tr>
                <td>通知类型</td>
                <td>{{if eq .task.NotifyType 1}}短信{{end}} {{if eq .task.NotifyType 0}}邮件{{end}}</td>
                <td></td>
            </tr>

            <tr>
                <td>通知用户</td>
                <td>
                {{range $k, $v := .adminInfo}}
                    {{$v.RealName}} &nbsp;&nbsp;&nbsp;
                {{end}}
                </td>
                <td></td>
            </tr>

            {{end}}

            <tr>
                <td>创建时间</td>
                <td>{{.CreateTime}}</td>
                <td></td>
            </tr>

            <tr>
                <td>创建人</td>
                <td>{{.CreateName}}</td>
                <td></td>
            </tr>

            <tr>
                <td>修改时间</td>
                <td>{{.UpdateTime}}</td>
                <td></td>
            </tr>

            <tr>
                <td>最后修改人</td>
                <td>{{.UpdateName}}</td>
                <td></td>
            </tr>

            </tbody>
        </table>
        <input type="hidden" name="id" id="id" value="{{.task.Id}}">
    </div>

</div>
<script>
    layui.use(['form','element','layer','jquery'],function(){
        var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
        var $ = layui.jquery;
        var id = $("#id").val();
        var error_info = "{{.flash.error}}";
        if(error_info){
            layer.msg(error_info,{icon: 2,shade:0.3},function () {
                window.history.go(-1)
            })
            return;
        }
        $('.layui-btn-container button').on('click',function () {
            var event = $(this).attr('lay-filter');
            if (event==='edit'){
                var status =" {{.task.Status}}";
                if(status==1){
                    layer.msg("运行状态无法编辑任务，请先暂停任务");
                    return;
                }
                window.location.href="/task/edit?id="+id
            }else if(event==='log'){
                window.location.href="/tasklog/list?task_id="+id;
            }else if(event==='copy'){
                window.location.href="/task/copy?id="+id;
            }else if (event==='run'){
                layer.confirm("测试执行任务，注意不要超时，请确认执行", {icon: 3, title:'提示'}, function(index){
                    layer.load();
                    $.post('/task/ajaxrun', {id:id}, function (out) {
                        if (out.status == 0) {
                            layer.msg("操作成功",{icon: 1,shade:0.3,time:1000},function () {
                                window.location.href="/tasklog/list?task_id="+id
                            })
                        } else {
                            layer.msg(out.message)
                            return
                        }
                    }, "json");
                    setTimeout(function(){
                        layer.closeAll('loading');
                    }, 2000);
                    layer.close(index);
                });
            }else if (event==='audit' || event==='start' || event==='pause' || event==="nopass"){
                $.post('/task/ajax'+event, {id:id}, function (out) {
                    if (out.status == 0) {
                        layer.msg("操作成功",{icon: 1,shade:0.3,time:1000},function () {
                            window.location.reload()
                        })
                    } else {
                        layer.msg(out.message)
                        return
                    }
                }, "json");
                return
            }else{
                layer.msg("操作不存在")
            }
        })




        //但是，如果你的HTML是动态生成的，自动渲染就会失效
        //因此你需要在相应的地方，执行下述方法来手动渲染，跟这类似的还有 element.init();
        form.render();
    });
</script>